<?php
$NOTE_ID = (1<<0);
$NOTE_USER_ID = (1<<1);
$NOTE_UUID = (1<<2);
$NOTE_TITLE = (1<<3);
$NOTE_CONTENT = (1<<4);
$NOTE_CREATE_TIME = (1<<5);
$NOTE_MODIFY_TIME = (1<<6);
$NOTE_ATTRIBUTE	= (1<<7);
$NOTE_VERSION = (1<<8);

$client = new SoapClient(null, array('location' => "http://localhost:8888",'uri' => "urn:netbook"));
function login($client,$mail,$passwd)
{
	try {
		$sessionid = $client->__call("login",array(new SoapParam($mail,"mail"),new SoapParam($passwd,"passwd")));
	}
	catch (Exception $e) {
		$ERROR = $e->faultstring;
		return 0;
	}
	return $sessionid;
}
function logout($client,$uuid)
{
	try {
		if (!$client->__call("logout",array(new SoapParam($uuid,"session"))))
			return 1;
	}
	catch (Exception $e) {
		print $e->faultstring;
		return 0;
	}
	return 1;
}
function getMyNoteNumber($client,$session)
{
	return($client->__call("getMyNoteNumber",array(new SoapParam($session,"session"))));
}
function getMyNoteList($client,$session,$start,$count,$field)
{
	$start_u = new SoapVar($start,XSD_UNSIGNEDINT);
	$count_u = new SoapVar($count,XSD_UNSIGNEDINT);
	$field_u = new SoapVar($field,XSD_UNSIGNEDINT);

	$result = $client->__call("getMyNoteList",
			array(new SoapParam($session,"session"),
			new SoapParam($start_u,"start"),
			new SoapParam($count_u,"count"),
			new SoapParam($field_u,"field")));
	for ($i=0; $i<$count; $i++)
	{
		$result[$i]->title = iconv("UTF-8","Latin1",$result[$i]->title);
		$result[$i]->content = iconv("UTF-8","Latin1",$result[$i]->content);
	}
	return $result;
}
function getUserSharedNoteNumber($client,$session,$mail)
{
	return($client->__call("getUserSharedNoteNumber",array(new SoapParam($session,"session"),new SoapParam($mail,"mail"))));
}
function getUserSharedNoteList($client,$session,$mail,$start,$count,$field)
{
	$start_u = new SoapVar($start,XSD_UNSIGNEDINT);
	$count_u = new SoapVar($count,XSD_UNSIGNEDINT);
	$field_u = new SoapVar($field,XSD_UNSIGNEDINT);
	
	$result = $client->__call("getUserSharedNoteList",
			array(new SoapParam($session,"session"),
			new SoapParam($mail,"mail"),
			new SoapParam($start_u,"start"),
			new SoapParam($count_u,"count"),
			new SoapParam($field_u,"field")));
	for ($i=0; $i<$count; $i++)
	{
		$result[$i]->title = iconv("UTF-8","Latin1",$result[$i]->title);
		$result[$i]->content = iconv("UTF-8","Latin1",$result[$i]->content);
	}
	return $result;
}
function getAllSharedNoteNumber($client,$session)
{
	return($client->__call("getAllSharedNoteNumber",array(new SoapParam($session,"session"))));
}
function getAllSharedNoteList($client,$session,$start,$count,$field)
{
	$start_u = new SoapVar($start,XSD_UNSIGNEDINT);
	$count_u = new SoapVar($count,XSD_UNSIGNEDINT);
	$field_u = new SoapVar($field,XSD_UNSIGNEDINT);

	$result = $client->__call("getAllSharedNoteList",
			array(new SoapParam($session,"session"),
			new SoapParam($start_u,"start"),
			new SoapParam($count_u,"count"),
			new SoapParam($field_u,"field")));
	for ($i=0; $i<$count; $i++)
	{
		$result[$i]->title = iconv("UTF-8","Latin1",$result[$i]->title);
		$result[$i]->content = iconv("UTF-8","Latin1",$result[$i]->content);
	}
	return $result;
}
function getUserPublicNoteNumber($client,$session,$mail)
{
	return($client->__call("getUserPublicNoteNumber",array(new SoapParam($session,"session"),new SoapParam($mail,"mail"))));
}
function getUserPublicNoteList($client,$session,$mail,$start,$count,$field)
{
	$start_u = new SoapVar($start,XSD_UNSIGNEDINT);
	$count_u = new SoapVar($count,XSD_UNSIGNEDINT);
	$field_u = new SoapVar($field,XSD_UNSIGNEDINT);

	$result = $client->__call("getUserPublicNoteList",
			array(new SoapParam($session,"session"),
			new SoapParam($mail,"mail"),
			new SoapParam($start_u,"start"),
			new SoapParam($count_u,"count"),
			new SoapParam($field_u,"field")));
	for ($i=0; $i<$count; $i++)
	{
		$result[$i]->title = iconv("UTF-8","Latin1",$result[$i]->title);
		$result[$i]->content = iconv("UTF-8","Latin1",$result[$i]->content);
	}
	return $result;
}
function getAllPublicNoteNumber($client,$session)
{
	return($client->__call("getAllPublicNoteNumber",array(new SoapParam($session,"session"))));
}
function getAllPublicNoteList($client,$session,$start,$count,$field)
{
	$start_u = new SoapVar($start,XSD_UNSIGNEDINT);
	$count_u = new SoapVar($count,XSD_UNSIGNEDINT);
	$field_u = new SoapVar($field,XSD_UNSIGNEDINT);


	$result = $client->__call("getAllPublicNoteList",
			array(new SoapParam($session,"session"),
			new SoapParam($start_u,"start"),
			new SoapParam($count_u,"count"),
			new SoapParam($field_u,"field")));
	for ($i=0; $i<$count; $i++)
	{
		$result[$i]->title = iconv("UTF-8","Latin1",$result[$i]->title);
		//$result[$i]->content = iconv("UTF-8","Latin1",$result[$i]->content);
	}
	return $result;
}
function removeMyNote($client,$session,$uuid)
{
	return $client->__call("removeMyNote",array(new SoapParam($session,"session"),new SoapParam($uuid,"uuid")));
}
function getNoteById($client,$session,$noteid,$field)
{
	$noteid_u = new SoapVar($noteid,XSD_UNSIGNEDLONG);
	$field_u = new SoapVar($field,XSD_UNSIGNEDINT);
	
	$result = $client->__call("getNoteById",
			array(new SoapParam($session,"session"),
			new SoapParam($noteid_u,"note_id"),
			new SoapParam($field_u,"field")));
	return $result;
}


try {
	$session = login($client,"test@test.com","test123");
}
catch (Exception $e) {
	print $e->faultstring;
}
try {
	$num = getMyNoteNumber($client,$session);
}
catch (Exception $e) {
	print $e->faultstring;
}
try {
	$result = getMyNoteList($client,$session,0,$num,(1<<9)-1);
}
catch (Exception $e) {
	print $e->faultstring;
}

//var_dump( $result);



?>
